<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>29comonent 标签</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>

<body>
    <h1>29comonent component 标签</h1>
    <a href="../index.html">返回</a>
    <hr />
    <div id="app">

        <component v-bind:is="who">
        </component>
        <button @click="change">变化一下</button>
    </div>
    <script type="text/javascript">
        var componentA = {
            template: `
                <p style="color:red">This is A!</p>
            `
        }

        var componentB = {
            template: `
                <p style="color:green">This is B!</p>
            `
        }
        var componentC = {
            template: `
                <p style="color:blue">This is C!</p>
            `
        }
        var componentD = {
            template: `
                <p style="color:pink">This is D!</p>
            `
        }

        var app = new Vue({
            el: "#app",
            data: {
                who: "componentD"
            },
            components: {
                "componentA": componentA,
                "componentB": componentB,
                "componentC": componentC,
                "componentD": componentD
            },
            methods: {
                change: function () {
                    if (this.who == "componentA") {
                        this.who = "componentB"
                    } else if (this.who == "componentB") {
                        this.who = "componentC"
                    } else if (this.who == "componentC") {
                        this.who = "componentD"
                    } else {
                        this.who = "componentA"
                    }
                }
            }
        })
    </script>
</body>

</html>